<template>
  <div>
    <el-table :data="courses" height="550" border style="width: 100%" highlight-current-row @current-change="handleCurrentChange">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="cno" label="课程号" width="180"></el-table-column>
      <el-table-column prop="cname" label="课程名" width="180"></el-table-column>
      <el-table-column prop="cpre" label="先修课程" width="180"></el-table-column>
      <el-table-column fixed="right" label="操作" width="200">
        <template slot="header" slot-scope="scope">
          <el-button @click="handleAdd" type="primary" size="mini">添加</el-button>
        </template>
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.$index, scope.row)" type="primary" size="mini">编辑</el-button>
          <el-button @click="handleDelete(scope.$index, scope.row)" type="danger" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'CourseComponent',
  data () {
    return {
      dialog: false,
      courses: []
    }
  },
  mounted () {
    this.$get('/course/list')
      .then(response => {
        this.courses = response.data
      }).catch(() => {
        this.$message.error('Can not get all course')
      })
  },
  methods: {
    handleCurrentChange (row) {
      // console.log(JSON.stringify(row))
    },
    handleAdd () {
      this.dialog = true
    },
    handleEdit (index, row) {
      this.$message.info(index + JSON.stringify(row))
    },
    handleDelete (index, row) {
      this.$message.success(index + JSON.stringify(row))
    }
  }
}
</script>

<style scoped>

</style>
